package com.tjbank.cssys.mybatis.impl;

import com.tjbank.cssys.mybatis.IamPermissionDao;
import com.tjbank.cssys.mybatis.entity.IamPermission;
import com.tjbank.cssys.mybatis.entity.IamPermissionKey;
import com.tjbank.cssys.mybatis.mapper.IamPermissionMapper;
import com.tjbank.cssys.mybatis.sqlbuilder.IamPermissionSqlBuilder;
import java.util.List;
import javax.annotation.Resource;

import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * IamPermissionDaoImpl
 * 
 * @author PG(Auto Generator)
 * @version V2.0
 */
@Service
public class IamPermissionDaoImpl implements IamPermissionDao {
    @Resource
    private IamPermissionMapper iamPermissionMapper;

    public IamPermissionDaoImpl() {
        super();
    }

    @Override
    public List<IamPermission> selectListBySqlBuilderWithBLOBs(IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        return iamPermissionMapper.selectBySqlBuilderWithBLOBs(iamPermissionSqlBuilder);
    }

    @Override
    public List<IamPermission> selectListBySqlBuilder(IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        return iamPermissionMapper.selectBySqlBuilder(iamPermissionSqlBuilder);
    }

    @Override
    public IamPermission selectBySqlBuilderWithBLOBs(IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        List<IamPermission> listIamPermissions = selectListBySqlBuilderWithBLOBs(iamPermissionSqlBuilder);
        if (listIamPermissions == null || listIamPermissions.isEmpty()) {
            return null;
        } else if (listIamPermissions.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamPermissions.get(0);
    }

    @Override
    public IamPermission selectBySqlBuilder(IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        List<IamPermission> listIamPermissions = selectListBySqlBuilder(iamPermissionSqlBuilder);
        if (listIamPermissions == null || listIamPermissions.isEmpty()) {
            return null;
        } else if (listIamPermissions.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamPermissions.get(0);
    }

    @Override
    public IamPermission selectByPrimaryKey(IamPermissionKey iamPermissionKey) throws RuntimeException {
        return iamPermissionMapper.selectByPrimaryKey(iamPermissionKey);
    }

    @Override
    public long countBySqlBuilder(IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        return iamPermissionMapper.countBySqlBuilder(iamPermissionSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insert(IamPermission iamPermission) throws RuntimeException {
        return iamPermissionMapper.insert(iamPermission);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insertUseBatch(List<IamPermission> listIamPermissions) throws RuntimeException {
        return iamPermissionMapper.insertUseBatch(listIamPermissions);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilder(IamPermission iamPermission, IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        iamPermissionSqlBuilder.setUpdateObject(iamPermission);
        return iamPermissionMapper.updateBySqlBuilder(iamPermissionSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilderSelective(IamPermission iamPermission, IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        iamPermissionSqlBuilder.setUpdateObject(iamPermission);
        return iamPermissionMapper.updateBySqlBuilderSelective(iamPermissionSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKey(IamPermission iamPermission) throws RuntimeException {
        return iamPermissionMapper.updateByPrimaryKey(iamPermission);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKeySelective(IamPermission iamPermission) throws RuntimeException {
        return iamPermissionMapper.updateByPrimaryKeySelective(iamPermission);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteBySqlBuilder(IamPermissionSqlBuilder iamPermissionSqlBuilder) throws RuntimeException {
        return iamPermissionMapper.deleteBySqlBuilder(iamPermissionSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteByPrimaryKey(IamPermissionKey iamPermissionKey) throws RuntimeException {
        return iamPermissionMapper.deleteByPrimaryKey(iamPermissionKey);
    }
}